<?php

class MasterController extends BaseController {

    //ADD Features
    public function getAddfeatures() {
        $addfeatures = DB::table('ref_additional_features')
                ->where('additional_features_isdelete', '=', 0)
                ->paginate(10);
        return View::make('admin.master.addfeatures')->with('addfeatures', $addfeatures);
    }

    public function postAddfeatures() {
        if (Input::get('filter') == 'type') {
            $addfeatures = DB::table('ref_additional_features')
                    ->where('additional_features_isdelete', '=', 0)
                    ->where('additional_features_type', '=', Input::get('typeby'))
                    ->paginate(10);
        } else {
            $addfeatures = DB::table('ref_additional_features')
                    ->where('additional_features_isdelete', '=', 0)
                    ->where('additional_features_name', 'LIKE', '%' . Input::get('name') . '%')
                    ->paginate(10);
        }
        return View::make('admin.master.addfeatures')->with('addfeatures', $addfeatures);
    }

    public function postAddaddfeatures() {
        $addaddfeatures = refadditionalfeatures::create(Input::all());
        return Redirect::to('/master/addfeatures')->with('message', 'Data fitur tambahan berhasil ditambahkan');
    }

    public function postEditaddfeatures($id) {
        $editaddfeatures = refadditionalfeatures::find($id);
        $editaddfeatures->additional_features_type = Input::get('additional_features_type');
        $editaddfeatures->additional_features_name = Input::get('additional_features_name');
        $editaddfeatures->additional_features_price = Input::get('additional_features_price');
        $editaddfeatures->additional_features_unit = Input::get('additional_features_unit');
        $editaddfeatures->save();
        return Redirect::to('/master/addfeatures')->with('message', 'Data fitur tambahan berhasil diubahn');
    }

    public function postDeleteaddfeatures() {
        $addfeatures = DB::table('ref_additional_features')
                ->get();
        foreach ($addfeatures as $addfeatures) {
            if (Input::get($addfeatures->additional_features_id) == '1') {
                $id = Input::get($addfeatures->additional_features_id);
                $addfeatures = DB::table('ref_additional_features')
                        ->where('additional_features_id', '=', $addfeatures->additional_features_id)
                        ->update(array('additional_features_isdelete' => 1));
            }
        }
        return Redirect::to('/master/addfeatures')->with('message', 'Data fitur tambahan berhasil dihapus');
    }

    //paper
    //ADD Features
    public function getPapers() {
        $papers = DB::table('ref_papertype')
                ->where('papertype_isdelete', '=', 0)
                ->paginate(10);
        return View::make('admin.master.papers')->with('papers', $papers);
    }

    public function postPapers() {
        if (Input::get('filter') == 'type') {
            $papers = DB::table('ref_papertype')
                    ->where('papertype_isdelete', '=', 0)
                    ->where('papertype_type', '=', Input::get('typeby'))
                    ->paginate(10);
        } else {
            $papers = DB::table('ref_papertype')
                    ->where('papertype_isdelete', '=', 0)
                    ->where('papertype_name', 'LIKE', '%' . Input::get('name') . '%')
                    ->paginate(10);
        }
        return View::make('admin.master.papers')->with('papers', $papers);
    }

    public function postAddpapers() {
        $addpapers = refpapertypes::create(Input::all());
        return Redirect::to('/master/papers')->with('message', 'Data kertas berhasil ditambahkan');
    }

    public function postEditpapers($id) {
        $editpapers = refpapertypes::find($id);
        $editpapers->papertype_type = Input::get('papertype_type');
        $editpapers->papertype_name = Input::get('papertype_name');
        $editpapers->save();
        return Redirect::to('/master/papers')->with('message', 'Data kertas berhasil diubahn');
    }

    public function postDeletepapers() {
        $papers = DB::table('ref_papertype')
                ->get();
        foreach ($papers as $papers) {
            if (Input::get($papers->papertype_id) == '1') {
                $id = Input::get($papers->papertype_id);
                $papers = DB::table('ref_papertype')
                        ->where('papertype_id', '=', $papers->papertype_id)
                        ->update(array('papertype_isdelete' => 1));
            }
        }
        return Redirect::to('/master/papers')->with('message', 'Data kertas berhasil dihapus');
    }

}